<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            height: 300px;
            width: 500px;
            /* outline不占空间 */
            outline: 1px solid red;
            margin: 100px auto;
            position: relative;
        }
        .inner {
            position: absolute;
            left: 50px;
            top: 50px;
            height: 100px;
            width: 100px;
            background: red;
        }
    </style>
</head>
<body>

    <div class="container">
        <div class="inner"></div>
    </div>

    <script src="./jq.js"></script>
    <script>
        // 使用position方法拿到元素针对父元素的left top
        // console.log($('.inner').position());
        // 设置相对父元素的位置
        console.log($('.inner'));

        /**
         * @param el<jq element>
         * @param position<{ top: number, left: number }>
        */
        function setPosition (el, position) {
            const parent2doc = el.parent().offset();
            const newPosition2doc = {
                left: parent2doc.left + position.left,
                top: parent2doc.top + position.top,
            };
            el.offset(newPosition2doc);
        }

        setPosition($('.inner'), { left: 100, top: 100 });

    </script>
</body>
</html>